package com.cysion.study.adapter

import android.content.Context
import android.content.Intent
import android.net.Uri
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.cysion.other._setOnClickListener
import com.cysion.study.R
import com.cysion.study.entity.Studentlist
import com.cysion.study.ktbox.Box
import com.cysion.study.ktbox.base.BaseAdapter
import com.cysion.study.ktbox.base.BaseViewHolder
import com.cysion.study.ktbox.base.ITEM_CLICK
import com.cysion.study.ktbox.image.RoundTransform
import kotlinx.android.synthetic.main.item_activity_detail_item.view.*
import kotlinx.android.synthetic.main.item_activity_detail_item.view.img_avatar
import kotlinx.android.synthetic.main.item_activity_detail_item.view.iv_call
import kotlinx.android.synthetic.main.item_activity_detail_item.view.tv_name
import kotlinx.android.synthetic.main.item_activity_detail_item.view.tv_sign
import kotlinx.android.synthetic.main.item_class_detail.view.*

class ActivityDetailItemAdapter(mEntities: MutableList<Studentlist>, mContext: Context) :
    BaseAdapter<Studentlist>(mEntities, mContext) {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder<Studentlist> {

        return ProMoneyHolder(
            LayoutInflater.from(mContext).inflate(R.layout.item_activity_detail_item, parent, false)
        )
    }


    class ProMoneyHolder(itemView: View) : BaseViewHolder<Studentlist>(itemView) {
        override fun fillData(obj: Studentlist, position: Int) {
            itemView?.apply {
                itemView.tv_name.text = obj.name
//                Glide.with(context).load(obj.headImageUrl).into(img_avatar)

                Glide.with(Box.context).load(obj.headImageUrl)
                    .apply(RequestOptions.placeholderOf(R.mipmap.default_head))
                    .apply(RequestOptions.bitmapTransform(RoundTransform(6)))
                    .into(img_avatar)
                itemView.setOnClickListener {
                    mOnTypeClickListener?.invoke(obj, position, ITEM_CLICK)
                }

                if (obj.status == "0") {//学生状态 状态:0、未签订；1、已签到；2、请假；3、接送时间更改；
                    tv_sign.text = "签到"
                    tv_sign.isEnabled=true
                    tv_sign.background=resources.getDrawable(R.drawable.blue_bg)
                } else if (obj.status == "1") {
                    tv_sign.text = "已签到"
                    tv_sign.background=resources.getDrawable(R.drawable.back_green)
                    tv_sign.isEnabled=false
                } else if (obj.status == "2") {
                    tv_sign.text = "请假"
                }


                iv_call.setOnClickListener(View.OnClickListener {
                    //拨打电话
                    val intent = Intent()
                    intent.action = Intent.ACTION_DIAL//dial是拨号的意思
                    intent.data = Uri.parse("tel:" + obj.phone)//这个tel不能改，后面的数字可以随便改
                    intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
                    context.startActivity(intent)
                })

                tv_sign._setOnClickListener {
                    //学生状态 状态:0、未签到；1、已签到；2、请假；3、接送时间更改；
                    if (obj.status == "0") {
                        mOnTypeClickListener?.invoke(obj, position, agree)
                    }else if (obj.status == "1") {
                        mOnTypeClickListener?.invoke(obj, position, refuse)
                    }
                }


            }

        }

    }

    companion object {
        //点击事件
        const val preview = 2000
        const val refuse = 2001
        const val agree = 2003
    }


}



